import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import 'lib_cloud_storage_method_channel.dart';

abstract class LibCloudStoragePlatform extends PlatformInterface {
  /// Constructs a LibCloudStoragePlatform.
  LibCloudStoragePlatform() : super(token: _token);

  static final Object _token = Object();

  static LibCloudStoragePlatform _instance = MethodChannelLibCloudStorage();

  /// The default instance of [LibCloudStoragePlatform] to use.
  ///
  /// Defaults to [MethodChannelLibCloudStorage].
  static LibCloudStoragePlatform get instance => _instance;

  /// Platform-specific implementations should set this with their own
  /// platform-specific class that extends [LibCloudStoragePlatform] when
  /// they register themselves.
  static set instance(LibCloudStoragePlatform instance) {
    PlatformInterface.verifyToken(instance, _token);
    _instance = instance;
  }

  Future<String?> getPlatformVersion() {
    throw UnimplementedError('platformVersion() has not been implemented.');
  }

  /**
   * 谷歌授权登录
   */
  Future<GoogleLoginResult> startGoogleLogin({String? clientID});

  /**
   * 拉取云盘文件列表, 根据文件前缀
   */
  Future<FileList> fetchGoogleDriveFileList(String email, String prefix);

  /**
   * 根据fileId 拉取指定的云盘文件
   */
  Future<String> fetchGoogleDriveFileById(String email, String fileId);

  /**
   * 上传到谷歌云盘：
   * 参数1：传到云盘的文件名字
   * 参数2： 文件内容
   *
   * 返回值：文件id
   */
  Future<String> uploadToGoogleCloud(
      String email, String fileName, String fileContent);
}

class GoogleLoginResult {
  String email; //谷歌邮箱
  String idToken; //谷歌token
  String expirationDate; //iOS端，谷歌授权过期时间
  GoogleLoginResult(this.email, this.idToken, {this.expirationDate = ''});
}

class FileList {
  List<GoogleDriveFile> dataList;
  FileList(this.dataList);
}

class GoogleDriveFile {
  String fileName;
  String fileId;

  GoogleDriveFile(this.fileId, this.fileName);
}
